package com.gzx.risk.core.apis.result;

import java.time.LocalDate;
import java.time.format.DateTimeFormatter;

import org.apache.commons.lang3.StringUtils;

import com.gzx.risk.core.apis.context.AgeCalculator;
import com.gzx.risk.core.apis.context.DaysCalculator;

import lombok.Data;
import lombok.EqualsAndHashCode;
import lombok.ToString;

@Data
@ToString(callSuper = true)
@EqualsAndHashCode(callSuper = true)
public class MainResult extends RiskResult {
	private String name;// 姓名
	private String id;// 身份证
	private String phone;// 手机号码
	private String authDate;
	private String idLastdate;// 身份证截止有效期
	private String lastRefuseDate;// 系统最后一次拒绝时间
    private String city; //收货地 市

	public int getAge() {
		return AgeCalculator.calculateAge(id.substring(6, 14));
	}

	// 身份证前两位
	public String getArea() {
		return id.substring(0, 2);
	}

	// 身份证是否失效
	// false：失效
	// true：有效
	public boolean getIdLoss() {
		if (idLastdate == null || idLastdate.length() != 8) {
			throw new RuntimeException("身份证有效期错误");
		}
		DateTimeFormatter formatter = DateTimeFormatter.ofPattern("yyyyMMdd");
		LocalDate date = LocalDate.parse(idLastdate, formatter);
		LocalDate currentDate = LocalDate.now();
		if (date.isAfter(currentDate)) {
			return true;
		}
		return false;
	}

	// 最后一次拒绝天数
	public int getLastRefuseDays() {
		if (StringUtils.isEmpty(lastRefuseDate)) {
			return 0;
		}
		return DaysCalculator.calculateDays(lastRefuseDate);
	}

	// 累计拒绝次数
	public int getRefuseCount() {
		return 0;
	}
}
